﻿namespace ViaConvert.Csv
{
    using System.Collections.Generic;
    using System.Linq;

    public class Converter
    {
        public static Model.Xml.AddressInfo ToXmlModel(List<Model.Csv.AddressInfo> models)
        {
            Model.Xml.AddressInfo list = new Model.Xml.AddressInfo();
            
            List<Model.Xml.City> citys = new List<Model.Xml.City>();

            IEnumerable<IGrouping<string, string>> cityGroup = models.GroupBy(x => x.CityCode, x => x.CityName);

            foreach (IGrouping<string, string> itemGroup in cityGroup)
            {
                string Name = string.Empty;

                foreach (string name in itemGroup)
                {
                    Name = name;
                }

                Model.Xml.City city = new Model.Xml.City();
                city.code = itemGroup.Key;
                city.name = Name;
                citys.Add(city);
            }

            List<Model.Xml.District> districts = new List<Model.Xml.District>();
            foreach(Model.Xml.City c  in citys)
            {
                var ddd = models.Where(x=> x.CityCode==c.code & x.CityName == c.name);
                var DDcOUNT = ddd.Count();
                foreach(Model.Csv.AddressInfo ad in ddd)
                {
                    
                }
            }

            list.City = citys;
            
            return list;
        }
    }
}